﻿using AmazonMODEL;
using MODEL;
using SysController;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AmazonAPI
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }

        private void btnCategory_Click(object sender, EventArgs e)
        {
            //string str = SysController.HelperController.CategoryRequestReport();
            //string strGet=SysController.HelperController.CategoryGetReportRequestList();
            //string strReport= SysController.HelperController.CategoryGetReport();
            //string str = SysController.HelperController.CategoryConvert(@"E:\MWS\LargeAppliances_908799031-20150904091631.xml");
            //int i = -1;
            try
            {
                MessageBox.Show("Test");
                foreach (var appkey in SystemController.RunAccount)
                {
                    MessageBox.Show(appkey.AccountInfoName);
                     
                    List<ReportsInfo> listReport = SystemController.GetReportsInfo(appkey.AccountInfoID, ReportProcessingStatus._DONE_).Take(100).ToList();
                    if (listReport == null || listReport.Count < 1)
                        continue;
                    List<ReportsInfo> list = new List<ReportsInfo>();
                    foreach (var ls in listReport)
                    {
                        ReportsInfo model = ReportsController.GetReport(appkey, ls);
                        model.IsDel = false;
                        model.UpdateTime = DateTime.Now;
                        model.UpdateUser = "GetReport";
                        model.ReportProcessingStatus = ReportProcessingStatus.Complete.ToString();
                        list.Add(model);
                    }
                    bool IsAgain = true;
                Again: int row = SystemController.ModifyReportsInfo(list);
                    if (row < 1)
                    {
                        if (IsAgain)
                        {
                            IsAgain = false;
                            goto Again;
                        }
                        continue;
                    }
                }
            }
            catch (Exception ex )
            {
                MessageBox.Show(ex.Message);
            }
           
        }
    }
}
